package com.seean.clock.common;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.io.Serializable;

/**
 * @authur wsx
 * @date 2019/8/14 10:52
 */
@JsonSerialize() //不要NULL,如果字段是NULL的话，就不会被序列化
public class ServerResponse<T> implements Serializable {
    /**
     * 返回状态
     */
    private Boolean status;
    /**
     * 错误码/正确码
     */
    private Integer code;
    /**
     * 消息.
     */
    private String msg;
    /**
     * 具体的内容.
     */
    private T data;


    public static ServerResponse success(String msg,Object data){
        ServerResponse ServerResponse = new ServerResponse();
        ServerResponse.setMsg(msg);
        ServerResponse.setStatus(true);
        ServerResponse.setCode(200);
        ServerResponse.setData(data);
        return ServerResponse;
    }

    public static ServerResponse success(){
        ServerResponse ServerResponse = new ServerResponse();
        ServerResponse.setStatus(true);
        ServerResponse.setCode(200);
        return ServerResponse;
    }

    public static ServerResponse error(Integer code,String msg){
        ServerResponse ServerResponse = new ServerResponse();
        ServerResponse.setStatus(false);
        ServerResponse.setCode(code);
        ServerResponse.setMsg(msg);
        return ServerResponse;
    }

    public static ServerResponse error(String msg){
        ServerResponse ServerResponse = new ServerResponse();
        ServerResponse.setStatus(false);
        ServerResponse.setCode(500);
        ServerResponse.setMsg(msg);
        return ServerResponse;
    }


    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}